// src/crudOption/service/serviceList.js
export default () => {
  // ===== 搜索 =====
  const searchOption = ref({
    formConfig: {
      name: { label: "类目名称", component: "el-input" },
      createTime: {
        label: "新增时间",
        component: "el-date-picker",
        type: "daterange",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
        unlinkPanels: true,
      },
      updateTime: {
        label: "编辑时间",
        component: "el-date-picker",
        type: "daterange",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
        unlinkPanels: true,
      },
      updateName: {
        label: "操作人员",
        component: "el-input",
      },
      categoryStatus: {
        label: "状态",
        component: "el-select",
        defaultValue: "",
        dicData: [
          { label: "全部", value: "" },
          { label: "已启用", value: 1 },
          { label: "已停用", value: 0 },
        ],
        dicProps: { label: "label", value: "value" },
        placeholder: "全部",
        clearable: true,
      },
    },
  });

  // ===== 表格/表单 =====
  const tableOption = ref(
    Utils.tools.deleteSearchConfig({
      addTitle: "新增服务类目",
      editTitle: "编辑服务类目",
      dialogWidth: "30%", // 20% 在窄屏可能太小，这里给个像素更稳；按需改回

      page: false, // 树表不分页
      stripe: false,
      align: "left",
      menu: true,
      menuWidth: 250,
      addBtn: false,
      editBtn: false,
      delBtn: false,

      // 树配置
      rowKey: "id",
      tree: true,
      defaultExpandAll: false,
      children: "children",

      labelWidth: 100,

      /**
       * 弹窗表单（与原型一致）
       */
      group: [
        {
          column: {
            // 1) 上级类目（只读展示）
            parentName: {
              label: "上级类目",
              span: 24,
              display: true, // 只在表单里显示
              addDisplay: true,
              editDisplay: true,
            },
            // 2) 类目名称（必填 ≤6 字）
            name: {
              label: "类目名称",
              span: 24,
              placeholder: "请输入类目名称",
              type: "input",
              maxlength: 6,
              clearable: true,
              rules: [{ required: true, message: "请输入类目名称", trigger: "blur" }],
            },

            // 3) 类目排序（必填 正整数，越小排越前）
            sortNo: {
              label: "类目排序",
              span: 24,
              type: "number",
              controls: false,
              placeholder: "请输入排序，限制正整数，越小排越前",
              rules: [
                { required: true, message: "请输入类目排序", trigger: "blur" },
                {
                  validator: (_r, v, cb) => (/^[1-9]\d*$/.test(String(v)) ? cb() : cb(new Error("请输入正整数"))),
                  trigger: "blur",
                },
              ],
            },
          },
        },
      ],

      /**
       * 列表列
       */
      column: {
        // 隐藏字段：parentId（“加下级”时由页面赋值）
        parentId: { label: "父级ID", display: false, addDisplay: false, editDisplay: false, hide: true },

        name: { label: "类目名称", minWidth: 160, display: false },

        sortNo: { label: "排序", width: 120, type: "number", display: false },

        createTime: {
          label: "新增时间",
          minWidth: 170,
          type: "datetime",
          valueFormat: "YYYY-MM-DD HH:mm:ss",
          addDisplay: false,
          editDisplay: false,
        },

        updateTime: {
          label: "最近编辑时间",
          minWidth: 170,
          type: "datetime",
          valueFormat: "YYYY-MM-DD HH:mm:ss",
          addDisplay: false,
          editDisplay: false,
        },

        updateName: {
          label: "操作人员",
          minWidth: 120,
          addDisplay: false,
          editDisplay: false,
        },

        categoryStatus: {
          label: "展示状态",
          minWidth: 120,
          display: false, // 列表里你用自定义 slot + 开关，所以这里不渲染内置
        },
      },
    })
  );

  return { searchOption, tableOption };
};
